package com.liliya.dao;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.activation.DataSource;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public abstract class BaseDao {
	public ResultSet rs = null;
	public PreparedStatement pstm = null;
	public Connection conn = null;

	public Connection getConn(){
		try {
			conn = new ComboPooledDataSource().getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	//关闭
	public void close() {
		try {
			if(rs != null) {
				rs.close();
				rs = null;
			}
			if(pstm != null) {
				pstm.close();
				pstm = null;
			}
			if(conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
